#!/usr/bin/sh

# Test for temporal algebra in LatLon location.
rm /tmp/vinput1_test.txt
rm /tmp/vinput2_test.txt
rm /tmp/vinput3_test.txt
rm /tmp/vinput4_test.txt

# Create random area test maps.
for i in {1..60}
  do
    if [[ "$i" -le 20 ]]; then
      echo vtestpoint1_$i >> /tmp/vinput1_test.txt
      v.random --o -z output=vtestpoint1_$i n=3 seed=$i+1
      v.voronoi --o input=vtestpoint1_$i output=vtestpoint1_$i
    elif [ "$i" -gt 20 ] && [ "$i" -le 40 ]; then
      echo vtestpoint2_$i >> /tmp/vinput2_test.txt
      v.random --o -z output=vtestpoint2_$i n=3 seed=$i+1
      v.voronoi --o input=vtestpoint2_$i output=vtestpoint2_$i
    else
      echo vtestpoint3_$i >> /tmp/vinput3_test.txt
      echo vtestpoint4_$i >> /tmp/vinput4_test.txt
      v.random --o -z output=vtestpoint3_$i n=3 seed=$i+1
      v.voronoi --o input=vtestpoint3_$i output=vtestpoint3_$i
      v.random --o -z output=vtestpoint4_$i n=3 seed=$i+1
      v.voronoi --o input=vtestpoint4_$i output=vtestpoint4_$i
    fi
  done

# Create STVDS and register test maps.
t.create --o output=vtest1 type=stvds title="test dataset" descr="test dataset"
t.create --o output=vtest2 type=stvds title="test dataset" descr="test dataset"
t.create --o output=vtest3 type=stvds title="test dataset" descr="test dataset"
t.create --o output=vtest4 type=stvds title="test dataset" descr="test dataset"

t.register -i --o type=vect input=vtest1 file=/tmp/vinput1_test.txt increment="1 days" start="2013-01-01"
t.register -i --o type=vect input=vtest2 file=/tmp/vinput2_test.txt increment="1 days" start="2013-01-10"
t.register -i --o type=vect input=vtest3 file=/tmp/vinput3_test.txt increment="3 days" start="2013-01-01"
t.register -i --o type=vect input=vtest4 file=/tmp/vinput4_test.txt increment="3 days" start="2013-01-10"

t.merge --o inputs=vtest2,vtest3 output=vtest5 type=stvds

# Test different options.
python t.vect.mapcalc.py --o expression='V = vtest1 & vtest2' basename="vmap"
t.vect.list input=V column=name,start_time,end_time
python t.vect.mapcalc.py --o expression='V = vtest1 {equal|during,+&} vtest3' basename="vmap"
t.vect.list input=V column=name,start_time,end_time
python t.vect.mapcalc.py --o expression='B = buff_p(test1,10)' basename="bmap"
t.vect.list input=B column=name,start_time,end_time
python t.vect.mapcalc.py --o expression='B = buff_p(test2,1) {equal|during,|^} vtest4' basename="bmap"
t.vect.list input=B column=name,start_time,end_time
python t.vect.mapcalc.py --o expression='B = if(td(vtest1) == 1 || start_date() >= "2010-01-10", vtest2)' basename="bmap"
